import unittest

import ddt

from common.functions import open_browser
from page.frontpage.shoppcart_pageX import ShoppingCart


class ShopTestCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        # 打开浏览器
        driver=open_browser()
        # 创建购物车页面（shoppcart_page）的对象
        cls.cart=ShoppingCart(driver)
        # 登录到主页
        cls.cart.login()

    # 查看购物车
    def test_01_get_cart(self):
        self.cart.get_cart()

    # 购物车增加商品
    def test_02_add_cart(self):
        self.cart.add_shop1()
        self.cart.add_shop2()
        self.cart.add_shop3()
        text = self.cart.get_cart_text()
        self.assertEqual(text,'购物车(3)',msg='数据不匹配')

    # 购物车增加商品数量以及更新购物车
    def test_03_refresh(self):
        self.cart.alter_cart('3')
        text = self.cart.get_cart_text()
        self.assertEqual(text,'购物车(5)',msg='数据不匹配')

    # 购物车里删除商品
    def test_04_delete(self):
        self.cart.del_shop()
        text = self.cart.get_cart_text()
        self.assertEqual(text, '购物车(2)', msg='数据不匹配')

    # 将商品移出购物车，放进收藏夹
    def test_05_collect(self):
        self.cart.collect()
        text = self.cart.get_cart_text()
        self.assertEqual(text, '购物车(1)', msg='数据不匹配')

    # 清空购物车
    def test_06_clear(self):
        self.cart.clear_cart()

    # 关闭浏览器
    @classmethod
    def tearDownClass(cls) -> None:
        cls.cart.get_cart()
        cls.cart.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)







